home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / Chip_2004-11_cd1.bin / zkuste / dolby / download / dvdlab / DVDlabProRC2b.exe / {app} / Extras / Script / Gradient.talk < prev    next >
Text File  |  2004-03-22  |  3KB  |  108 lines

  1. /*    Simple Gradient 1.0
  2.     by Oscar, 11 Dec 2003
  3.     
  4.     To run this: DROP the Script from Assets to the Object in Menu.
  5.     
  6.     this example creates a simple color gradient on any object
  7.     Note: because of the bitmap merging, the text will become not-editable after you apply this
  8. */
  9.  
  10. // Get the current menu and selected object when you drag and drop script
  11. // Note: if testing from Script editor make sure you have just one menu opened on desktop,
  12. //       in such case the MenuGetCurSel will return currently opened menu 
  13. menu = MenuGetCurSel() 
  14. // VTS menu 1..255, VMG menu 10001..10255 
  15.  
  16. // show the current menu on top of all others
  17. MenuActivate(menu)
  18.  
  19. object= ObjectGetCurSel(menu) 
  20.  
  21. if (object==0) then
  22.     print "No object Selected"
  23.     end
  24. endif
  25.  
  26. // get default color and type from registry
  27. color1 = LoadInteger("GradColor1",RGB(0,0,0))
  28. color2 = LoadInteger("GradColor2",RGB(255,0,0))
  29. type = LoadInteger("GradType",0)
  30.  
  31. input "COLOR:From Color ", color1,"COLOR:To Color ", color2,"Direction:Vertical|Horizontal",type //"CHECK:/FILE:/COLOR:/Combo:item1|item2... 
  32.     
  33. //allow cancel    
  34. if bCancelInput then
  35.     trace "Cancelled"
  36.     end
  37. endif
  38.     
  39. // save color and grad type to registry
  40. SaveInteger("GradColor1",color1)
  41. SaveInteger("GradColor2",color2)
  42. SaveInteger("GradType",type)
  43.     
  44. //get the image buffer from object and store it in buffer 1
  45. ImgGrabObject(1,menu,object) // imgNum = temporary image buffer 1,2 or 3
  46.  
  47. imgW = ImgGetWidth(1) 
  48. imgH = ImgGetHeight(1)
  49.  
  50. // calculate the color additions per each y or x
  51. // the color parameters are combined r,g,b, to get each component use GETR, GETB, GETC
  52.  
  53. //vertical
  54. steps = imgH
  55.  
  56. //horizontal
  57. if type==1 then
  58.     steps = imgW
  59. endif
  60.  
  61. // one of the parameter in equation has to be float or else the result will be integer
  62. // we will amake the steps float number. 
  63. cr = (GETR(color2)-GETR(color1))/FLOAT(steps)
  64. cg = (GETG(color2)-GETG(color1))/FLOAT(steps)
  65. cb = (GETB(color2)-GETB(color1))/FLOAT(steps)
  66.  
  67. // trace is same as print, but it will appear only in the Output window in editor
  68. // it will never pop up window
  69. trace "Steps =",steps, "  cr =",cr,"  cg =",cg,"  cb =",cb
  70.  
  71. // this is interpreter so it is slow!
  72. // show some progress or else people will see nothing happening for while
  73. ProgressBar(0,steps,"Creating Gradient")
  74.  
  75. // set the initial valuse FROM color
  76. RR = GETR(color1)
  77. GG = GETG(color1)
  78. BB = GETB(color1)
  79.  
  80. // loop through y or x dirrection depending on the type
  81. if (type==0) then
  82.     for y=1 to imgH
  83.         
  84.         ProgressSetPos(y)
  85.     
  86.         RR=RR+cr
  87.         GG=GG+cg
  88.         BB=BB+cb
  89.         // fill whole row at once (much faster than loop through all pixels
  90.         ImgFillRow(1,y,RGB(RR,GG,BB))
  91.     next y
  92. else
  93.  
  94.     for x=1 to imgW
  95.         ProgressSetPos(x)
  96.     
  97.         RR=RR+cr
  98.         GG=GG+cg
  99.         BB=BB+cb
  100.         // fill whole row at once (much faster than loop through all pixels
  101.         ImgFillCol(1,x,RGB(RR,GG,BB))
  102.     next x
  103. endif
  104.  
  105. // now put the img buffer 1 into the object!
  106. // all objects will be converted to bitmap objects (text will be no more editable)
  107. ImgSetToObject(1,menu,object)